package tp.pr5.items;

import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;

/**
 * The superclass of every type of item. It contains the common information for all the items and it defines the interface that the items must match
 * @author VICTOR & HENAR
 */

public abstract class Item implements Comparable<Item>{
	private String id;
	private String description;
	
	/**
	 * Builds an item from a given identifier and description
	 * @param id - Item identifier
	 * @param description - Item description
	 */
	public Item(String id, String description) {
		this.id = id;
		this.description = description;
	}
	
	/**
	 * Checks if the item can be used. Subclasses must override this method
	 * @return true if the item can be used
	 */
	
	public abstract boolean canBeUsed();
	
	/**
	 * Try to use the item with a robot in a given place. It returns whether the action was completed. Subclasses must override this method
	 * @param r - The robot that uses the item
	 * @param p- The Place where the item is used
	 * @return true if the action was completed. Otherwise, it returns false
	 */
	public abstract boolean use(RobotEngine r, NavigationModule nav);
	
	/**
	 * Return the item identifier
	 * @return The item identifier
	 */
	public String getId()
	{
		return this.id;
	}
	
	/**
	 * Return the item description
	 * @return The item description
	 */
	public String getDescription()
	{
		return this.description;
	}
	
	/**
	 * Generates a String with the Item description
	 * @see Object.toString()
	 */
	public String toString()
	{
		return this.id + ": " + this.description;
	}
	
	public int compareTo(Item otherItem) { 
	     return this.id.compareToIgnoreCase(otherItem.getId());
	}
}
